package com.godo.hadoop.config;

import org.apache.hadoop.conf.Configuration;


/**
 * Utility to create Hadoop {@link Configuration}s that include Nutch-specific
 * resources.
 */
public class SpiderConfiguration {

//	private final static String KEY = SpiderConfiguration.class.getName();
	public static Configuration conf;

	private SpiderConfiguration(){	}

	/** Create a {@link Configuration} for Nutch. */
	public static Configuration create(){
		if (conf == null){
			conf = new Configuration();
			addSpiderResources(conf);
		}
		return conf;
	}

//	public static Configuration get(ServletContext application) {
//		Configuration conf = (Configuration) application.getAttribute(KEY);
//		if (conf == null) {
//			conf = create();
//			Enumeration<?> e = application.getInitParameterNames();
//			while (e.hasMoreElements()) {
//				String name = (String) e.nextElement();
//				conf.set(name, application.getInitParameter(name));
//			}
//			application.setAttribute(KEY, conf);
//		}
//		return conf;
//	}

	/** Add the standard Nutch resources to {@link Configuration}. */
	public static Configuration addSpiderResources(Configuration conf)
	{
		conf.addResource("spider.xml");
		return conf;
	}

}
